package com.lywz.biz.dao.food.impl;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.lywz.biz.common.dao.AbstractBaseDao;
import com.lywz.biz.common.entity.goodfood.Food;
import com.lywz.biz.dao.food.FoodDao;
import com.lywz.core.util.CommonDefaultCheck;

@Repository("foodDao")
public class FoodDaoImpl extends AbstractBaseDao implements FoodDao {

    /* (non-Javadoc)
     * @see com.lywz.biz.dao.food.FoodDao#getFoodByType(int)
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<Food> getFoodByType(int foodType, int begin, int count) throws Exception{
        Query query = session().getNamedQuery("Food.queryFoodByType");
        query.setParameter("foodType", (Integer) foodType);
        query.setFirstResult((begin-1) * count);
        query.setMaxResults(count);
        return (List<Food>) CommonDefaultCheck.checkDefault(query.list());
    }

    /* (non-Javadoc)
     * @see com.lywz.biz.dao.food.FoodDao#getTypedFoodList(int, int)
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<Food> getTypedFoodList(int foodType, int limit) throws Exception {
        Query query = session().getNamedQuery("Food.queryTypedFoodList");
        query.setParameter("foodType", (Integer)foodType);
        query.setMaxResults(limit);
        return (List<Food>) CommonDefaultCheck.checkDefault(query.list());
        
    }

    /* (non-Javadoc)
     * @see com.lywz.biz.dao.food.FoodDao#getTopSpecialFoodList(int)
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<Food> getTopSpecialFoodList(int limit) throws Exception {
        Query query = session().getNamedQuery("Food.queryTopSpecalFoodList");
        query.setMaxResults(limit);
        return (List<Food>) CommonDefaultCheck.checkDefault(query.list());
    }

    /* (non-Javadoc)
     * @see com.lywz.biz.dao.food.FoodDao#getOtherFoodList(int, int)
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<Food> getOtherFoodList(int foodType, int limit) throws Exception {
        Query query = session().getNamedQuery("Food.queryMainFoodList");
        query.setParameter("foodType", foodType);
        query.setMaxResults(limit);
        return (List<Food>) CommonDefaultCheck.checkDefault(query.list());
    }

    /* (non-Javadoc)
     * @see com.lywz.biz.dao.food.FoodDao#getAllSpecialFoodList()
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<Food> getAllSpecialFoodListByAddTime() throws Exception {
        Query query = session().getNamedQuery("Food.querySpecalFoodList");
        return (List<Food>) CommonDefaultCheck.checkDefault(query.list());
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<Food> getAllTypedFoodListByAddTime(int foodType) throws Exception {
        Query query = session().getNamedQuery("Food.queryAllTypedFoodListByAddTime");
        query.setParameter("foodType", foodType);
        return (List<Food>) CommonDefaultCheck.checkDefault(query.list());
    }

    /* (non-Javadoc)
     * @see com.lywz.biz.dao.food.FoodDao#getDrinkTeaListOrderByAddTime()
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<Food> getDrinkTeaListOrderByAddTime() throws Exception {
        Query query = session().getNamedQuery("Food.queryDrinkTeaListOrderByAddTime");
        return (List<Food>) CommonDefaultCheck.checkDefault(query.list());
    }
    
    
}
